#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.${artifactId}.web;

import org.springframework.http.HttpStatus;

/**
 * @Author: shenyang
 * @CreateTime: 2022-09-30  17:11
 * @Description: TODO
 * @Version: 1.0
 */
public class ResultFactory {

    private ResultFactory() {
    }





    /**
     * 构造Http响应
     *
     *
     * @param code       body中code字段
     * @param msg        body中msg字段
     */
    public static <T> ResultData<T> build( int code, String msg) {
        return  new ResultData<>(code, msg);
    }

    /**
     * 构造Http响应，Http Status设为200
     *
     * @param code body中code字段
     * @param msg  body中msg字段
     * @param data body中data字段
     */
    public static <T> ResultData<T> build(int code, String msg, T data) {
        return  new ResultData<>(code, msg, data );
    }

    /**
     * 构造Http响应
     *
     * @param httpStatus Http响应状态码
     * @param code       body中code字段
     * @param msg        body中msg字段
     * @param data       body中data字段
     */
    public static <T> ResultData<T> build(HttpStatus httpStatus, int code, String msg, T data) {
        return  new ResultData<>(code, msg, data);
    }

    /**
     * 构造成功响应，Http Status设为200
     */
    public static <T> ResultData<T> success() {
        int success = ResultDataDetail.SUCCESS;
        String msg = ResultDataDetail.resultMap.get(success);
        return new ResultData<>(success, msg);
    }

    /**
     * 构造成功响应，Http Status设为200
     *
     * @param data body中data字段
     */
    public static <T> ResultData<T> success(T data) {
        int success = ResultDataDetail.SUCCESS;
        String msg = ResultDataDetail.resultMap.get(success);
        return new ResultData<>(ResultDataDetail.SUCCESS, msg, data);
    }

    /**
     * 构造成功响应，Http Status设为200
     *
     * @param msg  body中msg字段
     * @param data body中data字段
     */
    public static <T> ResultData<T> success(String msg, T data) {
        return  new ResultData<>(ResultDataDetail.SUCCESS, msg, data) ;
    }


    /**
     * 构造失败响应，Http Status设为200
     */
    public static <T> ResultData<T> failure() {
        int failure = ResultDataDetail.FAILURE;
        String msg = ResultDataDetail.resultMap.get(failure);
        return  new ResultData<>(failure, msg) ;
    }

    /**
     * 构造失败响应，Http Status设为200
     *
     * @param msg body中msg字段
     */
    public static <T> ResultData<T> failure(String msg) {
        return  new ResultData<>(ResultDataDetail.FAILURE, msg) ;
    }

    /**
     * 构造失败响应，Http Status设为200
     *
     * @param msg  body中msg字段
     * @param data body中data字段
     */
    public static <T> ResultData<T> failure(String msg, T data) {
        return  new ResultData<>(ResultDataDetail.FAILURE, msg, data) ;
    }

    /**
     * 构造失败响应，Http Status设为200
     *
     * @param code body中code字段
     * @param msg  body中msg字段
     * @param data body中data字段
     */
    public static <T> ResultData<T> failure(int code, String msg, T data) {
        return  new ResultData<>(code, msg, data) ;
    }




}
